package com.whg.demo.utils;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import java.io.File;

/**
 * @Author whg
 * @create 2023/9/28 17:41
 * @description：
 */
public class PdfCropBlankUtils {

    public static void  main(String [] args) {

        try {

            File pdfFile = new File("D:\\home\\tonlan\\static\\printTemplate\\test.pdf");
            PDDocument pdDocument = PDDocument.load(pdfFile);
            for (int i = 1; i <= pdDocument.getNumberOfPages(); i++) {
                PDFTextStripper stripper = new PDFTextStripper();
                stripper.setStartPage(i);
                stripper.setEndPage(i);
                String text = stripper.getText(pdDocument).replaceAll("visiblespace", " ");

                String[] lines = text.split("\n");
                System.out.println("Page Number " + i + " lines " + lines.length);
            }

        } catch(Exception e){
            System.out.print(e);
        }
    }
}
